package com.example.peibei.ui.adapter;

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.dingtao.common.bean.Dynamic;
import com.dingtao.common.bean.SquareDetail;
import com.dingtao.common.util.DateUtils;
import com.dingtao.common.util.GlideUtils;
import com.example.peibei.R;
import com.example.peibei.ui.utils.LevelImage;

import java.text.ParseException;
import java.util.List;

public class SquareDetailListAdapter extends BaseQuickAdapter<SquareDetail.RecordsDTO, BaseViewHolder> {
    String status;

    public SquareDetailListAdapter(@Nullable List<SquareDetail.RecordsDTO> data) {
        super(R.layout.item_square_detail_list, data);
    }

    @SuppressLint("CheckResult")
    @Override
    protected void convert(BaseViewHolder helper, SquareDetail.RecordsDTO item) {
        ImageView head = helper.getView(R.id.iv_head);
        Glide.with(getContext()).load(item.getMemberUrl()).apply(RequestOptions.bitmapTransform(new CircleCrop())).into(head);
        helper.setText(R.id.tv_name, item.getNickname()).setText(R.id.tv_dec, item.getContent()).setText(R.id.tv_adress, item.getReplyTime());
        List<String> imgUrls = item.getImgUrls();
        LinearLayout llImgs = helper.getView(R.id.ll_imgs);
        ImageView imgOne = helper.getView(R.id.iv_img_one);
        ImageView imgTwo = helper.getView(R.id.iv_img_two_dynamic);
        ImageView imgThree = helper.getView(R.id.iv_img_three);
        ImageView imgFour = helper.getView(R.id.iv_img_four);
        ImageView zan = helper.getView(R.id.zan);
        TextView zan_tv = helper.getView(R.id.zan_tv);
        TextView com_tv = helper.getView(R.id.com_tv);
        TextView time = helper.getView(R.id.time);
        time.setVisibility(View.GONE);
        if (imgUrls.size() > 0) {
            if (imgUrls.size() == 1) {
                imgFour.setVisibility(View.VISIBLE);
                llImgs.setVisibility(View.GONE);
                GlideUtils.loadImg(getContext(), imgUrls.get(0), 40, imgFour);
            } else {
                imgFour.setVisibility(View.GONE);
                llImgs.setVisibility(View.VISIBLE);
                if (imgUrls.get(0) != null && !imgUrls.get(0).equals("")) {
                    GlideUtils.loadImg(getContext(), imgUrls.get(0), 20, imgOne);
                } else {
                    imgOne.setVisibility(View.INVISIBLE);
                }
                if (imgUrls.size() > 1 && imgUrls.get(1) != null && !imgUrls.get(1).equals("")) {
                    GlideUtils.loadImg(getContext(), imgUrls.get(1), 20, imgTwo);
                } else {
                    imgTwo.setVisibility(View.INVISIBLE);
                }
                if (imgUrls.size() > 2 && imgUrls.get(2) != null && !imgUrls.get(2).equals("")) {
                    GlideUtils.loadImg(getContext(), imgUrls.get(2), 20, imgThree);
                } else {
                    imgThree.setVisibility(View.INVISIBLE);
                }
            }

        } else {
            llImgs.setVisibility(View.GONE);
            imgFour.setVisibility(View.GONE);
        }
        if (!item.isFollow()) {
            zan.setImageResource(R.mipmap.zan_img);
        } else {
            zan.setImageResource(R.mipmap.zan_yellow);
        }
        if (item.getFollowerCount()==0){
            zan_tv.setText("点赞");
        }else{
            zan_tv.setText(String.valueOf(item.getFollowerCount()));
        }
//        if (item.getComment() != 0) {
//            com_tv.setText(String.valueOf(item.getComment()));
//        } else {
//            com_tv.setText("评论");
//        }
    }
}
